<template>
	<view class="content">
		<movable-area class="movableArea">
			<movable-view class="movableView" :position="position" :x="x" :y="y" :direction="direction"
				:damping="damping" @tap="onTap" @touchend="onTouchend" @change="onChange">
				<view class="t-icon t-icon-a-addmusic-copy" style="width: 64rpx; height: 64rpx;"></view>
			</movable-view>
		</movable-area>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				x: 0,
				y: 400,
				x1: 0,
				x2: 0,
				y1: 0,
				y2: 0,
				move: {
					x: null,
					y: null
				}
			};
		},
		props: {
			damping: {
				type: Number,
				default: 10
			},
			direction: {
				type: String,
				default: 'all'
			},
			position: {
				type: Number,
				default: 4
			},
			url: {
				type: String
			}
		},
		mounted() {
			uni.getSystemInfo({
				success: (res) => {
					this.x1 = 0;
					this.x2 = parseInt(res.windowWidth) - 50;
					this.y1 = 0;
					this.y2 = parseInt(res.windowHeight) - 20;
					setTimeout(() => {
						if (this.position == 1 || this.position == 2) this.y = parseInt(this.y2 * 0.2);
						if (this.position == 3 || this.position == 4) this.y = parseInt(this.y2 * 0.8);
						if (this.position == 1 || this.position == 3) this.x = parseInt(this.x1);
						if (this.position == 2 || this.position == 4) this.x = parseInt(this.x2);
						this.move.x = this.x;
						this.move.y = this.y;
					}, 1000)
				}
			})
		},
		methods: {
			onChange(e) {
				this.move.x = e.detail.x;
				this.move.y = e.detail.y;
			},
			onTap(e) {
				console.log(this.url)
				uni.navigateTo({
					url: this.url
				})
			},
			onTouchend() {
				this.x = this.move.x;
				this.y = this.move.y;
				setTimeout(() => {
					if (this.move.x < this.x2 / 2) this.x = this.x1;
					else this.x = this.x2;
				}, 100)
			}
		},
	};
</script>

<style scoped>
	.content {
		position: relative;
		height: 100vh;
	}

	.movableArea {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		pointer-events: none;
		z-index: 999;
	}

	.movableView {
		pointer-events: auto;
		width: 100rpx;
		height: 100rpx;
		padding: 10rpx;
		border-radius: 100%;
	}

	.iconImage {
		display: block;
		width: 100rpx;
		height: 100rpx;
	}

	.contact {
		width: 50px;
		height: 50px;
		overflow: hidden;
		position: absolute;
		left: 0px;
		top: 0px;
		border-radius: 100%;
		opacity: 0;
	}
</style>